<?php
// include_once("/var/www/html/new/com.inc.php");
if (!class_exists("go_sql")){
include("/var/www/html/new/conf/le.je");
  $le=new go_sql();
  $le->connect();
}
$txt = file_get_contents('php://input');
//logfile($txt);

$ac='16ucom';
$pw='c33367701511b4f6020ec61ded352059';
$inside = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
	
 $txt='{"VerifyCode":"967f7d01549aec7b909cf34b9c57338d","Order16U":"894194","ActionTime":"2015-03-25 11:18:01","OrderCall":"3678359497","Tnumber":"1","OrderState":1}'; 

$data = json_decode($txt);
$ordern = $data->Order16U;
$num = $data->Tnumber;
$nowdate=$data->ActionTime;

$search_date=$inside->Order_Globle_Search("", "", "", "", "", "", "", "", "", "", "", "", "$ordern", "", "", "", "", "", "", "1", "0", "1", "0", "0", "", "0", "", "0", "", "", "", "0", "0", "0");
$c=simpleXML_load_string($search_date);
$aid = (string)$c->Rec->UUaid;
$select = "select * from uu_qunar_use where fid ='$aid' limit 1";
$GLOBALS['le']->query($select);
$GLOBALS['le']->fetch_assoc();
$supplierIdentity = $GLOBALS['le']->f('supplierIdentity');
$signkey = $GLOBALS['le']->f('signkey');

$string=<<<XML
<?xml version="1.0" encoding="UTF-8"?>
<request xsi:schemaLocation="http://piao.qunar.com/2013/QMenpiaoRequestSchema QMRequestDataSchema-2.0.1.xsd" xmlns="http://piao.qunar.com/2013/QMenpiaoRequestSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<header>
		<application>Qunar.Menpiao.Agent</application>
		<processor>SupplierDataExchangeProcessor</processor>
		<version>v2.0.1</version>
		<bodyType>NoticeOrderConsumedRequestBody</bodyType>
		<createUser>SupplierSystemName</createUser>
		<createTime>$nowdate</createTime>
		<supplierIdentity>$supplierIdentity</supplierIdentity>
	</header>
	<body xsi:type="NoticeOrderConsumedRequestBody">
		<orderInfo>
			<partnerorderId>$ordern</partnerorderId>
			<orderQuantity>$num</orderQuantity>
			<useQuantity>$num</useQuantity>
			<consumeInfo></consumeInfo>
		</orderInfo>
	</body>
</request>
XML;

$bstr=base64_encode($string);
 
$signed=strtoupper(md5($signkey.$bstr));

$arr=array('data'=>$bstr,'signed'=>$signed,'securityType'=>'MD5');
$post_arr = json_encode($arr);
$result = lmm_post('noticeOrderConsumed',$post_arr);
print_r($result);
if($result){
	echo 200;
}
function lmm_post($aq, $cq){
	$post_data = array(); 
	$post_data['method'] = $aq; 
	$post_data['requestParam'] = $cq; 
	//$url='http://piaoagentdev.qunar.com/api/external/supplierServiceV2.qunar'; 
	$url='http://piaoagentdev.qunar.com/api/external/supplierServiceV2.qunar';
	$o=""; 
	foreach ($post_data as $k=>$v){ 
	$o.= "$k=".urlencode($v)."&"; 
	} 
	$post_data=substr($o,0,-1);
	$ch = curl_init(); 
	curl_setopt($ch, CURLOPT_POST, 1); 
	curl_setopt($ch, CURLOPT_HEADER, 0); 
	curl_setopt($ch, CURLOPT_URL,$url); 
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
	// curl_exec($ch);
	$reponse = curl_exec($ch);
	curl_close($ch);
	return $reponse;
}
function logfile($txt){
	$fp = fopen("qunar_return.txt","a");
	flock($fp, LOCK_EX) ; 
	fwrite($fp,$txt."\n");
	flock($fp, LOCK_UN);
	fclose($fp);
}
?>